/*
 * @Author: xiaosihan 
 * @Date: 2022-07-11 07:51:56 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2025-09-25 00:11:06
 */
import { useEffect } from 'react';
import { Button } from 'antd';
import homeRenderer from "./homeRender";
import styles from './index.module.less';
import homeStore from './homeStore'; // 导入homeStore以确保消息监听器被初始化
import utils from '@/utils/utils';

const Home = () => {
    useEffect(() => {
        // 页面初始化逻辑
    }, []);

    // 按钮点击事件处理函数
    const handleStartInspection = () => {
        console.log('开始巡检');
        // 实际项目中添加开始巡检的逻辑
        window.postMessage('startInspection', "*");
    };

    const handleEndInspection = () => {
        console.log('结束巡检');
        // 实际项目中添加结束巡检的逻辑
        window.postMessage('endInspection', "*"); // 使用"*"作为目标源（仅用于开发环境）
    };

    return (
        <div className={styles.home}>
            <div ref={dom => homeRenderer.setContainer(dom)} className={styles.container}></div>

            {/* 底部绝对定位的按钮区域 */}
            {
                utils.isDev &&
                <div className={styles.buttonContainer}>

                    <Button
                        type="primary"
                        size="large"
                        onClick={() => window.postMessage('startCheck', "*")}
                        className={styles.checkButton}
                    >
                        开始查档
                    </Button>
                    
                    <Button
                        type="primary"
                        size="large"
                        onClick={() => window.postMessage('endCheck', "*")}
                        className={styles.checkButton}
                    >
                        结束查档
                    </Button>

                    <Button
                        type="primary"
                        size="large"
                        onClick={() => window.postMessage('startInventory', "*")}
                        className={styles.inventoryButton}
                    >
                        开始盘点
                    </Button>
                    <Button
                        danger
                        type="primary"
                        size="large"
                        onClick={() => window.postMessage('endInventory', "*")}
                        className={styles.inventoryButton}
                    >
                        结束盘点
                    </Button>


                    <Button
                        type="primary"
                        size="large"
                        onClick={handleStartInspection}
                        className={styles.inspectionButton}
                    >
                        开始巡检
                    </Button>
                    <Button
                        danger
                        size="large"
                        onClick={handleEndInspection}
                        className={styles.inspectionButton}
                    >
                        结束巡检
                    </Button>
                </div>
            }
        </div>
    );
}

export default Home;